<?php

define('BLOG_NAME', "Voluntarios Josefina Martinez");

function listBlogs($dir=''){
    $files = scandir(DIRECTORY_LISTING."/$dir", 1);

    foreach($files as $file){
        if($file == "." || $file == ".." || $file == ".svn")
            continue;

        if(is_dir(DIRECTORY_LISTING."/$file")){
            if($dir != '') $recurse = "$dir/$file";
            else $recurse = $file;
            listBlogs("$recurse");
        }
        else{
            list($month, $day, $year, $hour, $minute) =
                sscanf($file, "%s %d %d %d %d");

            print "<a href='index.php?blog=$dir/$file&title=$file".
                  "'>$month $day, $year $hour:$minute</a><br>";
        }
    }
}

function printBlog($blog){
    $dir = DIRECTORY_LISTING."/$blog";
    list($month, $day, $year, $hour, $minute) =
        sscanf($_GET['title'], "%s %d %d %d %d");

    $fp = fopen($dir, 'r');
    $data = fread($fp, filesize($dir));
    fclose($fp);
    
    print ('
	<html>
	<div class="content">
		
		<p>'.$data.'</p>	
	</div>	
	<div class="footer">
		<ul>
			<li class="comments"><a href="http://voluntariosjosefinam.forum-free.org">Foro</a></li>
		</ul>
	</div>
');
    
}

function displayTopBar(){
    if(!isset($_GET['blog'])){
        print("Pagina principal");
    }
    else{
        print("<a href='index.php'>Pagina principal</a>");
    }
}

function printListBlog($dir=''){
$files = scandir(DIRECTORY_LISTING."/$dir", 1);

	   foreach($files as $file){
        	if($file == "." || $file == ".." || $file == ".svn")
            	continue;
		if(is_dir(DIRECTORY_LISTING."/$file")){
            		if($dir != '') $recurse = "$dir/$file";
            		else $recurse = $file;
            		printListBLog("$recurse");
        	}
		else{
            		list($month, $day, $year, $hour, $minute) =
                	sscanf($file, "%s %d %d %d %d");
    			print "<h3>Fecha: $month $day, $year $hour:$minute</h3>";
			$poto=$DIRECTORY_LISTING."/$dir/$file";
			
			printBlog($poto);


       		}
	   }
}
function displayFecha(){
   
    $month = date("M");
    $day = date("d");
    $year = date("Y");
    $hour = date("H");
    $minute = date("i");
    print ('<html>
		<div id="date">
			'.$month.''. $day.'
		</div>
');
}
?>
